package com.eascs.spider.ant.common.kafka;

import java.util.Properties;

import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

/**
 * kafka生产者
 * @author hzp
 *
 */
public class KafkaProducer {
	
	public static final String TOPIC = "51job";
	private static Producer<String, Object> producer;
	
	public synchronized static void init(){
		if(producer != null)
			return ;
		Properties props = new Properties();
        props.put("bootstrap.servers", "172.29.13.121:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", EncodeingKafka.class.getName());
        producer = new org.apache.kafka.clients.producer.KafkaProducer<String, Object>(props);
	}
	
	public static void send(Object o){
		producer.send(new ProducerRecord<String, Object>(TOPIC, o));
	}
	
	public static void main(String[] args) {

	}
}
